<?php 

import("@.Public.UserCheck");
class UploadAction extends Action
{
	public function index()
	{
		$usercheck=new UserCheck();
		if($usercheck->isLogin())
		{
			if($_POST['submit']=='上传')//验证信息并跳转
			{
				import("ORG.Net.UploadFile");
				$upload = new UploadFile(); // 实例化上传类
				$upload->maxSize  =-1; // 设置附件上传大小
				$upload->savePath = './Upload/'; // 设置附件上传目录__ROOT__.'/Upload/'
				$upload->saveRule = $_SESSION['username'].$_FILES['file']['name'];
				$upload->allowExts  = array('mp4', 'ogg'); //
				if(!$upload->upload())
				//if(true)
				{ // 上传错误提示错误信息
					header("Content-type:text/html;charset=utf-8");
					echo $upload->getErrorMsg();
				}
				else
				{ 
					
					// 上传成功 获取上传文件信息
					$info =  $upload->getUploadFileInfo();
					$user=M('User_video');
					$user->create();
					$user->username=$_SESSION['username'];
					$user->videosize=$info[0]['size'];
					$user->viewtimes=0;
					$user->videodir=$info[0]['savename'];
					$user->scores=0;
					$user->screenshotdir=__ROOT__.'/videoshotimage/'.$info[0]['savename'].'.jpg';
					$user->add();
					// 获取视频截图
					if(extension_loaded('ffmpeg'))
					{//判断ffmpeg是否载入   
					$videopath=VIDEO_ABS_PATH.$info[0]['savename'];
					$mov = new ffmpeg_movie($videopath);//视频的路径     
					$ff_frame = $mov->getFrame(2);     
					$gd_image = $ff_frame->toGDImage();     
					$img=VIDEO_ABS_IMAGE_PATH.$info[0]['savename'].'.jpg';//要生成图片的绝对路径    
					imagejpeg($gd_image, $img);//创建jpg图像     
					imagedestroy($gd_image);//销毁一图像 
					}
					else{     
					  echo "ffmpeg没有载入";
					} 
					$this->redirect('index/index');
				}
				
				
			}
			else//显示注册表单
			{
				
				$this->display();
			}
		}
		else 
		{
			header("Content-type:text/html;charset=utf-8");
			$str='请登录！';
			$this->redirect('Index/login',array(),2,$str);
		}
	}
	
	
	
}





?>